home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
os2
/
pccts.zip
/
ANTLR.H
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-08
|
10KB
|
364 lines
/*
* a n t l r . h
*
* Define all of the stack setup and manipulation of $i, #i variables.
*
* Notes:
* The type 'Attrib' must be defined before entry into this .h file.
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* ANTLR 1.06
* Terence Parr
* Purdue University
* 1989-1992
*/
/* can make this a power of 2 for more efficient lookup */
#ifndef ZZLEXBUFSIZE
#define ZZLEXBUFSIZE 2000
#endif
#define zzOvfChk \
if ( zzasp <= 0 ) \
{ \
fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__); \
exit(-1); \
}
#ifndef ZZA_STACKSIZE
#define ZZA_STACKSIZE 400
#endif
#ifndef ZZAST_STACKSIZE
#define ZZAST_STACKSIZE 400
#endif
#ifdef LL_K
#define LOOKAHEAD \
int zztokenLA[LL_K]; \
char zztextLA[LL_K][ZZLEXBUFSIZE]; \
int zzlap = 0, zzlabase=0; /* labase only used for DEMAND_LOOK */
#else
#define LOOKAHEAD \
int zztoken;
#endif
#ifndef zzcr_ast
#define zzcr_ast(ast,attr,tok,text)
#endif
#ifdef DEMAND_LOOK
#define DemandLookData int zzdirty=1;
#else
#define DemandLookData
#endif
/* The zzStackOvfMsg error message is repeated often and therefore only one
* copy is made to save space.
*/
#ifdef LL_K
#ifdef __STDC__
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(int _tok, char *_text)\
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; \
int TCount=0, TComp=0; DemandLookData
#else
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(_tok, _text) int _tok; char *_text;\
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; \
int TCount=0, TComp=0; DemandLookData
#endif
#else
#ifdef __STDC__
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(int _tok, char *_text)\
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; \
int TCount=0, TComp=0; DemandLookData
#else
#define ANTLR_INFO \
Attrib zzempty_attr() {static Attrib a; return a;} \
Attrib zzconstr_attr(_tok, _text) int _tok; char *_text;\
{Attrib a; zzcr_attr((&a),_tok,_text); return a;} \
int zzasp=ZZA_STACKSIZE; \
char zzStackOvfMsg[]="fatal: attrib/AST stack overflow %s(%d)!\n"; \
Attrib zzaStack[ZZA_STACKSIZE]; \
int TCount=0, TComp=0; DemandLookData
#endif
#endif /* LL_k */
#ifdef LL_K
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead {zzdirty=LL_K; zzlap = zzlabase = 0;}
#else
#define zzPrimeLookAhead {int _i; for(_i=1;_i<=LL_K; _i++) \
{zzCONSUME;} zzlap = 0;}
#endif
#else
#ifdef DEMAND_LOOK
#define zzPrimeLookAhead zzdirty=1
#else
#define zzPrimeLookAhead zzgettok()
#endif
#endif /* LL_K */
#ifdef LL_K
#define zzenterANTLRf(f) \
zzlextext = &(zztextLA[0][0]); zzrdfunc( f ); zzPrimeLookAhead;
#define zzenterANTLR(f) \
zzlextext = &(zztextLA[0][0]); zzrdstream( f ); zzPrimeLookAhead;
#else
#define zzenterANTLRf(f) \
{static char zztoktext[ZZLEXBUFSIZE]; \
zzlextext = zztoktext; zzrdfunc( f ); zzPrimeLookAhead;}
#define zzenterANTLR(f) \
{static char zztoktext[ZZLEXBUFSIZE]; \
zzlextext = zztoktext; zzrdstream( f ); zzPrimeLookAhead;}
#endif
#define ANTLR(st, f) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLR(f); \
st; ++zzasp;
/*
#define ANTLR(st, f) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLR(f); \
st; ++zzasp; \
fprintf(stderr, "TCount %d, TComp %d; Ratio %f\n", \
TCount, TComp, \
((float)TComp)/TCount);
*/
#define ANTLRf(st, f) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLRf(f); \
st; ++zzasp;
/*#define ANTLRf(st, f) zzbufsize = ZZLEXBUFSIZE; \
zzenterANTLRf(f); \
st; ++zzasp; \
fprintf(stderr, "TCount %d, TComp %d; Ratio %f\n", \
TCount, TComp, \
((float)TComp)/TCount);
*/
#ifdef LL_K
#define zztext (&(zztextLA[zzlap][0]))
#else
#define zztext zzlextext
#endif
/* A r g u m e n t A c c e s s */
#define zzaCur (zzaStack[zzasp])
#define zzaRet (*zzaRetPtr)
#define zzaArg(v,n) zzaStack[v-n]
#define zzMakeAttr {zzOvfChk; --zzasp; zzcr_attr(&(zzaStack[zzasp]),LA(1),LATEXT(1));}
#ifdef zzdef0
#define zzMake0 {zzOvfChk; --zzasp; zzdef0(&(zzaStack[zzasp]));}
#else
#define zzMake0 {zzOvfChk; --zzasp;}
#endif
#define zzaPush(_v) {zzOvfChk; zzaStack[--zzasp] = _v;}
#ifndef zzd_attr
#define zzREL(t) zzasp=(t); /* Restore state of stack */
#else
#define zzREL(t) for (; zzasp<(t); zzasp++) \
{ zzd_attr(&(zzaStack[zzasp])); }
#endif
#ifdef DEMAND_LOOK
#ifdef LL_K
#define zzmatch(_t) \
{ \
if ( zzdirty==LL_K ) { \
zzCONSUME; \
} \
if ( LA(1)!=_t ) { \
zzBadText=zzMissText=LATEXT(1); \
zzMissTok=_t; zzBadTok=LA(1); \
zzMissSet=NULL; \
goto fail; \
} \
zzMakeAttr \
zzdirty++; \
zzlabase++; \
}
#else
#define zzmatch(_t) \
{ \
if ( zzdirty ) {zzCONSUME;} \
if ( LA(1)!=_t ) { \
zzBadText=zzMissText=LATEXT(1); \
zzMissTok=_t; zzBadTok=LA(1); \
zzMissSet=NULL; \
goto fail; \
} \
zzdirty = 1; \
zzMakeAttr \
}
#endif
#else
#define zzmatch(_t) \
{ \
if ( LA(1)!=_t ) { \
zzBadText=zzMissText=LATEXT(1); \
zzMissTok=_t; zzBadTok=LA(1); \
zzMissSet=NULL; \
goto fail; \
} \
zzMakeAttr \
}
#endif /* DEMAND_LOOK */
#ifdef GENAST
#define zzRULE Attrib *zzaRetPtr = &(zzaStack[zzasp-1]); \
unsigned *zzMissSet; int zzMissTok=0; \
unsigned zzBadTok; char *zzBadText=""; \
int zzErrk=1; \
char *zzMissText; zzASTVars
#else
#define zzRULE Attrib *zzaRetPtr = &(zzaStack[zzasp-1]); \
unsigned zzBadTok; char *zzBadText=""; \
int zzErrk=1; \
unsigned *zzMissSet; int zzMissTok=0; char *zzMissText
#endif
#ifdef GENAST
#define zzBLOCK(i) int i = zzasp - 1; int zztsp = zzast_sp
#define zzEXIT(i) zzREL(i); zzastREL; zzastPush(*_root);
#define zzLOOP(i) zzREL(i); zzastREL
#else
#define zzBLOCK(i) int i = zzasp - 1
#define zzEXIT(i) zzREL(i)
#define zzLOOP(i) zzREL(i)
#endif
#ifdef LL_K
#ifdef DEMAND_LOOK
#define LOOK(_k) {int i,stop=_k-(LL_K-zzdirty); for (i=1; i<=stop; i++) \
zzCONSUME;}
#define zzCONSUME {zzgettok(); zzdirty--; \
zzlap = (zzlap+1)&(LL_K-1); \
zzlextext = &(zztextLA[zzlap][0]);}
#else
#define zzCONSUME {zzgettok(); \
zzlap = (zzlap+1)&(LL_K-1); \
zzlextext = &(zztextLA[zzlap][0]);}
#endif
#else
#ifdef DEMAND_LOOK
#define LOOK(_k) if ( zzdirty) zzCONSUME;
#define zzCONSUME zzgettok(); zzdirty=0;
#else
#define zzCONSUME zzgettok();
#endif /* LL_K */
#endif /* LL_K */
#ifdef LL_K
#define NLA zztokenLA[zzlap&(LL_K-1)] /* --> next LA */
#define NLATEXT zztextLA[zzlap&(LL_K-1)] /* --> next text of LA */
#ifdef DEMAND_LOOK
#define LA(i) zztokenLA[(zzlabase+(i)-1)&(LL_K-1)]
#define LATEXT(i) (&(zztextLA[(zzlabase+(i)-1)&(LL_K-1)][0]))
#else
#define LA(i) zztokenLA[(zzlap+(i)-1)&(LL_K-1)]
#define LATEXT(i) (&(zztextLA[(zzlap+(i)-1)&(LL_K-1)][0]))
#endif
#else
#define NLA zztoken
#define NLATEXT zztext
#define LA(i) zztoken
#define LATEXT(i) zztext
#endif
/* F u n c t i o n T r a c i n g */
#ifndef zzTRACEIN
#define zzTRACEIN(r) fprintf(stderr, "enter rule \"%s\"\n", r);
#endif
#ifndef zzTRACEOUT
#define zzTRACEOUT(r) fprintf(stderr, "exit rule \"%s\"\n", r);
#endif
/* E x t e r n D e f s */
#ifdef __STDC__
extern Attrib zzempty_attr();
extern Attrib zzconstr_attr(int, char *);
extern void zzsyn(char *, unsigned, char *, unsigned *, int, int, char *);
extern int zzset_el(unsigned , unsigned *);
extern int zzset_deg(unsigned *);
extern void zzedecode(unsigned *);
extern void zzFAIL(int k, ...);
extern void zzresynch(unsigned *,unsigned);
#else
extern Attrib zzempty_attr();
extern Attrib zzconstr_attr();
extern void zzsyn();
extern int zzset_el();
extern int zzset_deg();
extern void zzedecode();
extern void zzFAIL();
extern void zzresynch();
#endif
extern int TCount, TComp;
extern char zzStackOvfMsg[];
extern char *zztokens[];
extern int zzasp;
extern int zzbufsize;
extern Attrib zzaStack[];
#ifdef LL_K
extern int zztokenLA[];
extern char zztextLA[][ZZLEXBUFSIZE];
extern int zzlap;
extern int zzlabase;
#else
extern int zztoken;
#endif
extern int zzdirty;